<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="审批人工号" prop="spUserId">
        <el-input
          v-model="queryParams.spUserId"
          placeholder="请输入审批人工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批人姓名" prop="spUserName">
        <el-input
          v-model="queryParams.spUserName"
          placeholder="请输入审批人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批流编码" prop="spCode">
        <el-input
          v-model="queryParams.spCode"
          placeholder="请输入审批流编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批流名称" prop="spName">
        <el-input
          v-model="queryParams.spName"
          placeholder="请输入审批流名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="审批节点" prop="spSolt">
        <el-input
          v-model="queryParams.spSolt"
          placeholder="请输入审批节点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批状态" prop="spFlag">
        <el-select v-model="queryParams.spFlag" placeholder="请选择审批状态" clearable>
          <el-option
            v-for="dict in dict.type.shenhe_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否审批完成" prop="isSpwc">
        <el-input
          v-model="queryParams.isSpwc"
          placeholder="请输入是否审批完成"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批建议" prop="spRemark">
        <el-input
          v-model="queryParams.spRemark"
          placeholder="请输入审批建议"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编号" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料子编号" prop="itemId">
        <el-input
          v-model="queryParams.itemId"
          placeholder="请输入物料子编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料分类" prop="classId">
        <el-input
          v-model="queryParams.classId"
          placeholder="请输入物料分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格型号" prop="spec">
        <el-input
          v-model="queryParams.spec"
          placeholder="请输入规格型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="物料单位" prop="unit">
        <el-input
          v-model="queryParams.unit"
          placeholder="请输入物料单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="托管标识" prop="isTuoguan">
        <el-input
          v-model="queryParams.isTuoguan"
          placeholder="请输入托管标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质量状态" prop="qualityState">
        <el-input
          v-model="queryParams.qualityState"
          placeholder="请输入质量状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用状态" prop="useState">
        <el-input
          v-model="queryParams.useState"
          placeholder="请输入使用状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库编号" prop="stockId">
        <el-input
          v-model="queryParams.stockId"
          placeholder="请输入仓库编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库名称" prop="stockName">
        <el-input
          v-model="queryParams.stockName"
          placeholder="请输入仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库区编码" prop="kuquCode">
        <el-input
          v-model="queryParams.kuquCode"
          placeholder="请输入库区编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库区名称" prop="kuquName">
        <el-input
          v-model="queryParams.kuquName"
          placeholder="请输入库区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库位编码" prop="kuweiCode">
        <el-input
          v-model="queryParams.kuweiCode"
          placeholder="请输入库位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商编码" prop="supplyId">
        <el-input
          v-model="queryParams.supplyId"
          placeholder="请输入供应商编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称" prop="supplyName">
        <el-input
          v-model="queryParams.supplyName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-s-check"
          size="mini"
          :disabled="single"
          @click="handleSp"
          v-hasPermi="['business:chukuSprw:sp']"
        >审批</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:chukuSprw:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:chukuSprw:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:chukuSprw:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:chukuSprw:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="chukuSprwList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="发起人工号" width="100" align="center" prop="userId" />
      <el-table-column label="发起人姓名" width="100" align="center" prop="userName" />
      <el-table-column label="审批人工号" width="100" align="center" prop="spUserId" />
      <el-table-column label="审批人姓名" width="100" align="center" prop="spUserName" />
      <el-table-column label="审批流编码" width="120" align="center" prop="spCode" />
      <el-table-column label="审批流名称" width="160" show-overflow-tooltip align="center" prop="spName" />
      <el-table-column label="审批节点" align="center" prop="spSolt" />
      <el-table-column label="出库单号" width="180" align="center" prop="danhao" />
      <el-table-column label="订单类型" align="center" prop="orderType" />
      <el-table-column label="物料分类" align="center" prop="classId" />
      <el-table-column label="物料名称" align="center" prop="itemName" />
      <el-table-column label="物料编号" width="150" align="center" prop="itemCode" />
      <el-table-column label="物料子编号" width="150" align="center" prop="itemId" />
      <el-table-column label="规格型号" width="120" align="center" prop="spec" />
      <el-table-column label="物料单位" align="center" prop="unit" />
      <el-table-column label="托管标识" align="center" prop="isTuoguan" />
      <el-table-column label="质量状态" align="center" prop="qualityState" />
      <el-table-column label="使用状态" align="center" prop="useState" />
      <el-table-column label="仓库编号" width="120" align="center" prop="stockId" />
      <el-table-column label="仓库名称" width="120" align="center" prop="stockName" />
      <el-table-column label="库区编码"width="120" align="center" prop="kuquCode" />
      <el-table-column label="库区名称" width="160" align="center" prop="kuquName" />
      <el-table-column label="库位编码" width="120" align="center" prop="kuweiCode" />
      <el-table-column label="供应商编码" width="120" align="center" prop="supplyId" />
      <el-table-column label="供应商名称" width="120" align="center" prop="supplyName" />
      <el-table-column label="审批流程" width="120" align="center" prop="isSpwc" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sp_iswc" :value="scope.row.isSpwc"/>
        </template>
      </el-table-column>
      <el-table-column label="审批状态" align="center" prop="spFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.shenhe_state" :value="scope.row.spFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="审批建议" width="120" show-overflow-tooltip align="center" prop="spRemark" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="handleSp(scope.row)"
            v-if="scope.row.isSpwc != 1"
            v-hasPermi="['business:chukuSprw:sp']"
          >审批</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:chukuSprw:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:chukuSprw:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出库待办任务对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审批人工号" prop="spUserId">
          <el-input v-model="form.spUserId" placeholder="请输入审批人工号" />
        </el-form-item>
        <el-form-item label="审批人姓名" prop="spUserName">
          <el-input v-model="form.spUserName" placeholder="请输入审批人姓名" />
        </el-form-item>
        <el-form-item label="审批流编码" prop="spCode">
          <el-input v-model="form.spCode" placeholder="请输入审批流编码" />
        </el-form-item>
        <el-form-item label="审批流名称" prop="spName">
          <el-input v-model="form.spName" placeholder="请输入审批流名称" />
        </el-form-item>
        <el-form-item label="审批节点" prop="spSolt">
          <el-input v-model="form.spSolt" placeholder="请输入审批节点" />
        </el-form-item>
        <el-form-item label="审批状态" prop="spFlag">
          <el-select v-model="form.spFlag" placeholder="请选择审批状态">
            <el-option
              v-for="dict in dict.type.shenhe_state"
              :key="dict.value"
              :label="dict.label" :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否审批完成" prop="isSpwc">
          <el-input v-model="form.isSpwc" placeholder="请输入是否审批完成" />
        </el-form-item>
        <el-form-item label="审批建议" prop="spRemark">
          <el-input v-model="form.spRemark" placeholder="请输入审批建议" />
        </el-form-item>
        <el-form-item label="物料分类" prop="classId">
          <el-input v-model="form.classId" placeholder="请输入物料分类" />
        </el-form-item>
        <el-form-item label="物料名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="物料号" prop="itemId">
          <el-input v-model="form.itemId" placeholder="请输入物料号" />
        </el-form-item>
        <el-form-item label="子图号" prop="itemCode">
          <el-input v-model="form.itemCode" placeholder="请输入子图号" />
        </el-form-item>
        <el-form-item label="规格型号" prop="spec">
          <el-input v-model="form.spec" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="物料单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入物料单位" />
        </el-form-item>
        <el-form-item label="托管标识" prop="isTuoguan">
          <el-input v-model="form.isTuoguan" placeholder="请输入托管标识" />
        </el-form-item>
        <el-form-item label="质量状态" prop="qualityState">
          <el-input v-model="form.qualityState" placeholder="请输入质量状态" />
        </el-form-item>
        <el-form-item label="使用状态" prop="useState">
          <el-input v-model="form.useState" placeholder="请输入使用状态" />
        </el-form-item>
        <el-form-item label="仓库编号" prop="stockId">
          <el-input v-model="form.stockId" placeholder="请输入仓库编号" />
        </el-form-item>
        <el-form-item label="仓库名称" prop="stockName">
          <el-input v-model="form.stockName" placeholder="请输入仓库名称" />
        </el-form-item>
        <el-form-item label="库区编码" prop="kuquCode">
          <el-input v-model="form.kuquCode" placeholder="请输入库区编码" />
        </el-form-item>
        <el-form-item label="库区名称" prop="kuquName">
          <el-input v-model="form.kuquName" placeholder="请输入库区名称" />
        </el-form-item>
        <el-form-item label="库位编码" prop="kuweiCode">
          <el-input v-model="form.kuweiCode" placeholder="请输入库位编码" />
        </el-form-item>
        <el-form-item label="供应商编码" prop="supplyId">
          <el-input v-model="form.supplyId" placeholder="请输入供应商编码" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="supplyName">
          <el-input v-model="form.supplyName" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 审批 -->
    <el-dialog :close-on-click-modal="false" :title="sp.title" :visible.sync="sp.open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="审批状态" prop="spFlag">
          <el-radio v-model="form.spFlag" label="1">同意</el-radio>
          <el-radio v-model="form.spFlag" label="2">不同意</el-radio>
        </el-form-item>
        <el-form-item label="审批意见" prop="spRemark">
          <el-input style="width: 500px"  type="textarea" v-model="form.spRemark" placeholder="请输入审批意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitSpForm">确 定</el-button>
        <el-button @click="sp.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listChukuSprw, getChukuSprw, delChukuSprw, addChukuSprw, updateChukuSprw,spChukuSprw } from "@/api/business/chukuSprw";

export default {
  name: "ChukuSprw",
  dicts: ['shenhe_state','sp_iswc'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库待办任务表格数据
      chukuSprwList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      sp:{
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        spUserId: null,
        spUserName: null,
        spCode: null,
        spName: null,
        spSolt: null,
        spFlag: null,
        isSpwc: null,
        spRemark: null,
        orderType: null,
        classId: null,
        itemName: null,
        itemId: null,
        itemCode: null,
        spec: null,
        unit: null,
        isTuoguan: null,
        qualityState: null,
        useState: null,
        stockId: null,
        stockName: null,
        kuquCode: null,
        kuquName: null,
        kuweiCode: null,
        supplyId: null,
        supplyName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询出库待办任务列表 */
    getList() {
      this.loading = true;
      listChukuSprw(this.queryParams).then(response => {
        this.chukuSprwList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryName: null,
        factoryCode: null,
        spUserId: null,
        spUserName: null,
        spCode: null,
        spName: null,
        spSolt: null,
        spFlag: null,
        isSpwc: null,
        spRemark: null,
        orderType: null,
        classId: null,
        itemName: null,
        itemId: null,
        itemCode: null,
        spec: null,
        unit: null,
        isTuoguan: null,
        qualityState: null,
        useState: null,
        stockId: null,
        stockName: null,
        kuquCode: null,
        kuquName: null,
        kuweiCode: null,
        supplyId: null,
        supplyName: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 审批 */
    handleSp(row) {
      this.reset();
      const id = row.id
      getChukuSprw(id).then(response => {
        this.form = response.data;
        this.form.spFlag="1"
        this.sp.open = true;
        this.sp.title = "出库代办任务审批";
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加出库待办任务";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getChukuSprw(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改出库待办任务";
      });
    },
    submitSpForm(){
      spChukuSprw(this.form).then(response => {
        this.$modal.alertSuccess("审批完成");
        this.sp.open = false;
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateChukuSprw(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addChukuSprw(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除出库待办任务编号为"' + ids + '"的数据项？').then(function() {
        return delChukuSprw(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/chukuSprw/export', {
        ...this.queryParams
      }, `chukuSprw_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
